Skip to content

Upgrade to CakePHP 5.4 and PHP 8.2+ - #19

Open
steinkel wants to merge 1 commit into
cakephp:masterfrom
CakeDC:feature/upgrade-cakephp-5-4-pr
Open

steinkel wants to merge 1 commit into
cakephp:masterfrom
CakeDC:feature/upgrade-cakephp-5-4-pr

Conversation

@steinkel

@steinkel steinkel commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Upgrade the CMS tutorial to CakePHP 5.4

Dependencies

  • CakePHP 5.2.9 -> 5.4.3, Authentication 3.3 -> 4.2, Authorization 3.4 -> 3.5, Migrations 4.8 -> 5.2, plus Bake, DebugKit and CodeSniffer.
  • PHP requirement is >=8.2, the minimum of CakePHP 5.4. The composer.lock is removed, like in the cakephp/app skeleton, so every install resolves versions for its own PHP.
  • PHPUnit (^11.5.3 || ^12.1.3 || ^13.0) and PHPStan are now dev dependencies (neither was declared before).

Breaking changes handled

  • Authentication 4: AbstractIdentifier::CREDENTIAL_* constants moved to PasswordIdentifier, and identifiers need an explicit className.
  • Migrations 5: AbstractMigration is replaced by BaseMigration.
  • Tests: IntegrationTestCase was removed, so tests use TestCase with IntegrationTestTrait.

Aligned with cakephp/app 5.4.0

  • Base files (bin, config, webroot, layouts, error and flash templates, phpcs.xml, phpstan.neon, CI workflow) now match the skeleton.
  • Application, routes, plugins (config/plugins.php) and AppController are merged with the tutorial's authentication and authorization code.
  • Models, entities, the policy and the Tags and Users templates were re-baked with Bake 3.8 and the app logic re-applied.

Fixes

  • TagsController and most of UsersController never called authorize() or skipAuthorization(). Each controller now declares its own public actions, and there are new TagPolicy, UserPolicy and UsersTablePolicy classes.
  • /articles/tagged/* required a login.
  • Article.slug was reported as required by newEntity() although it is derived from the title.
  • A failed article delete did not redirect.
  • Users::login uses redirectAfterLogin().
  • The related-articles links on the tag and user pages used the article id instead of the slug.
  • The tag pages offered a Delete link although nobody can delete tags.
  • /articles/tagged/a/b only used the first tag, the action now takes string ...$tags.
  • The tag form let any logged in user attach a tag to any article, bypassing the article policy.
  • The edit user form printed the stored password hash, and now an empty password keeps the current one.
  • A title that already exists now shows the problem under the Title field, and the slug cannot be mass assigned.
  • A title without letters or numbers produced an empty slug, so the article could not be opened. It is rejected now.
  • A title longer than 191 characters crashed on MySQL/MariaDB (the slug column is shorter), so the limit is 191.
  • The initial migration failed on MySQL/MariaDB because of the unsigned foreign key columns, Migrations 5 creates signed primary keys.
  • Non numeric ids in the tag and user URLs returned a 500, they return 404 now.
  • Tags that only differ by case were duplicated on SQLite and made the article save fail on MariaDB, they are matched ignoring the case on every database.
  • A tag string with only commas and spaces threw an exception, and emptying the tag field did not remove the tags.
  • Deleting a user left the articles orphaned, and the user stayed logged in. The articles are deleted too and the user is logged out.

Permissions

  • Anyone can read articles and tags, and sign up.
  • Logged in users can add articles and edit or delete their own.
  • Logged in users can add and edit tags, nobody can delete them.
  • Users can only see, edit or delete themselves.

Modernization

  • Typed docblocks and strict_types, Collection::implode() (5.4), Form->deleteLink() (5.2), the Authentication.Identity helper in the templates, __() in the templates and pagination in the articles list.
  • config/app_local.example.php keeps the SQLite default.

Tests and checks

  • New fixtures and tests for articles, tags, users, the policy and the tag logic (65 tests, also run against MariaDB).
  • composer test, composer cs-check and composer stan pass on PHP 8.2, 8.3, 8.4 and 8.5.
  • The CI workflow runs PHPUnit on PHP 8.2 to 8.5, and PHPCS and PHPStan on 8.5.

@steinkel
steinkel force-pushed the feature/upgrade-cakephp-5-4-pr branch 2 times, most recently from c72ef7a to f2c6563 Compare October 19, 2026 14:55
@steinkel
steinkel marked this pull request as ready for review October 19, 2026 15:18
@steinkel
steinkel force-pushed the feature/upgrade-cakephp-5-4-pr branch 4 times, most recently from 1c13216 to a109201 Compare October 19, 2026 16:33
- Update CakePHP to 5.4, Authentication to 4.2, Authorization to 3.5 and Migrations to 5.2, requiring PHP 8.2 or higher
- Align the base files with the cakephp/app 5.4 skeleton and re-bake the models, entities and templates
- Add the tag and user policies and make the public actions explicit in each controller
- Use sortable fields in the articles list and redirectAfterLogin in the login
- Add tests and fixtures for the articles, tags, users and policies, plus the PHPStan configuration and a CI workflow
@steinkel
steinkel force-pushed the feature/upgrade-cakephp-5-4-pr branch from a109201 to 51daab6 Compare October 19, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant